require 'xml_parsing'
require 'process_data'

# Please give absolute path to your pebble exported xml files.
basedir = "inputXML/"

Dir.chdir(basedir)
files = Dir.glob("*.xml");
files.each { |file|
  if File.file?(basedir + file)
    begin
      parsedPostData = parse_xml(basedir + file)
      id = process_post_data(parsedPostData)
      p "Processed postdata for the file: " + file
      parsedCommentData = parse_comments_nodelist(basedir + file)
      process_comment_data(parsedCommentData,id)
      p "Processed commentdata for the file: " + file
    rescue
      print "Error: ", $!, "\n"
    end
  else
    p "Error!.. Not a file. Add unit test!.."
  end
}

p "Processed " + files.length.to_s + " xml files successfully!"